﻿Imports MeoTom.Core.BLL
Imports MeoTom.Core

Partial Public Class UpImages_Verifying
    Inherits UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim util2 As New Utilities.Common()
        Dim previousPage As String = ""
        If Request.QueryString.ToString = vbNullString Then
            previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
        Else
            previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
        End If
        util2.ValidateLogin(previousPage)

        BindGrid()
    End Sub

    Public Sub BindGrid()
        Dim objPublicUpload As New PublicUploads
        Select Case Request.QueryString("action")
            Case "Update"
            Case Else
                objPublicUpload.Status = False
                objPublicUpload.TotalRecord = 5000
                objPublicUpload.OrderBy = "DESC"
                grvListImage.DataSource = objPublicUpload.GetUpload()
                grvListImage.DataBind()
        End Select
        objPublicUpload = Nothing
    End Sub

    Public Function DisplayImage(ByVal uploadBy As String, ByVal uploadName As String, ByVal createDate As DateTime) As String
        Dim strSource As String = Configs.UpUrl & "/Files/" & uploadBy & "/" & CreateDate.Year.ToString & "/" & Right("0" & CreateDate.Month.ToString, 2) & "/" & Right("0" & CreateDate.Day.ToString, 2)
        Return "<a href=""" & strSource & "/" & uploadName & """ target=""_blank""><img src=""" & strSource & "/130x0__" & uploadName & """ border=""0"" width=""130"" /></a>"
    End Function

    Private Sub GrvListImagePageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles grvListImage.PageIndexChanging
        grvListImage.PageIndex = e.NewPageIndex
        BindGrid()
    End Sub

    Private Sub btnApply_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnApply.Click
        Dim objPublicUpload As New PublicUploads
        If Request.Form("selectedAction0") = "1" Or Request.Form("selectedAction1") = "1" Then
            'Update Status
            For Each str As String In Regex.Split(Request.Form("cboCheckImage"), ",")
                objPublicUpload.UploadID = str
                objPublicUpload.UpdateUpload()
            Next
        ElseIf Request.Form("selectedAction0") = "2" Or Request.Form("selectedAction1") = "2" Then
            'Delete Image
            For Each str As String In Regex.Split(Request.Form("cboCheckImage"), ",")
                DeleteImage(objPublicUpload, str)
            Next
        End If
        BindGrid()
        objPublicUpload = Nothing
    End Sub

    Private Sub BtnApply2Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnApply2.Click
        btnApply_Click(sender, e)
    End Sub

    Public Sub DeleteImage(ByVal objPublicUpload As PublicUploads, ByVal uploadId As String)
        Dim objSrv As New Services.Up.ServiceImage()
        Dim splitter2 As Char() = {"|"c}
        objPublicUpload.UploadID = UploadID
        Dim strArr2 As String() = objPublicUpload.DeleteUpload().Split(splitter2)
        For i As Integer = 0 To strArr2.Length - 1
            If strArr2(i).Length > 5 Then
                'objUtil.DeleteFile(Configs.FolderUPImage & strArr2(i))
                objSrv.DeleteImage(strArr2(i))
            End If
        Next
        objSrv = Nothing
    End Sub
End Class